package com.chat.controller;

import com.chat.entry.dto.group.ReadAllMessageDTO;
import com.chat.entry.dto.group.ReadSingleMessageDTO;
import com.chat.result.Result;
import com.chat.service.IGroupMessageUnreadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 群未读表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-09-14
 */
@Api(tags = "群聊消息状态接口")
@Slf4j
@RestController
@RequestMapping("/api/group-message-unread")
@RequiredArgsConstructor
public class GroupMessageUnreadController {
    private final IGroupMessageUnreadService groupMessageUnreadService;

    @ApiOperation(value = "标记单条消息已读", notes = "根据用户id、群聊id、消息id，将该条消息以及更早的消息标记为已读")
    @PostMapping("/read/group-chat-message/single")
    public Result readSingleGroupChatMessage(
            @ApiParam(value = "单条消息已读请求参数", required = true) @RequestBody ReadSingleMessageDTO readSingleMessageDTO
    ) {
        return groupMessageUnreadService.singleMessageRead(readSingleMessageDTO);
    }

    @ApiOperation(value = "标记群聊所有消息已读", notes = "根据用户id、群聊id，将该群的所有未读消息标记为已读")
    @PostMapping("/read/group-chat-message/one/all")
    public Result readAllGroupChatMessage(
            @ApiParam(value = "一键已读请求参数", required = true) @RequestBody ReadAllMessageDTO readAllMessageDTO
    ) {
        return groupMessageUnreadService.readAllGroupChatMessage(readAllMessageDTO);
    }

    @ApiOperation(value = "标记所有消息已读（好友+群聊）", notes = "根据用户id，将该用户的所有未读消息（包含好友消息和群聊消息）全部标记为已读")
    @GetMapping("/read/all")
    public Result readAllMessage(
            @ApiParam(value = "用户ID", required = true) @RequestParam Integer userId
    ) {
        return groupMessageUnreadService.readAllMessage(userId);
    }
}
